--szykowanie kluczy
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity key_schedule is
    Port ( user_key : in  STD_LOGIC_VECTOR (255 downto 0);
		k0 : out  STD_LOGIC_VECTOR (127 downto 0);
		k1 : out  STD_LOGIC_VECTOR (127 downto 0);
		k2 : out  STD_LOGIC_VECTOR (127 downto 0);
		k3 : out  STD_LOGIC_VECTOR (127 downto 0);
		k4 : out  STD_LOGIC_VECTOR (127 downto 0);
		k5 : out  STD_LOGIC_VECTOR (127 downto 0);
		k6 : out  STD_LOGIC_VECTOR (127 downto 0);
		k7 : out  STD_LOGIC_VECTOR (127 downto 0);
		k8 : out  STD_LOGIC_VECTOR (127 downto 0);
		k9 : out  STD_LOGIC_VECTOR (127 downto 0);
		k10 : out  STD_LOGIC_VECTOR (127 downto 0);
		k11 : out  STD_LOGIC_VECTOR (127 downto 0);
		k12 : out  STD_LOGIC_VECTOR (127 downto 0);
		k13 : out  STD_LOGIC_VECTOR (127 downto 0);
		k14 : out  STD_LOGIC_VECTOR (127 downto 0);
		k15 : out  STD_LOGIC_VECTOR (127 downto 0);
		k16 : out  STD_LOGIC_VECTOR (127 downto 0);
		k17 : out  STD_LOGIC_VECTOR (127 downto 0);
		k18 : out  STD_LOGIC_VECTOR (127 downto 0);
		k19 : out  STD_LOGIC_VECTOR (127 downto 0);
		k20 : out  STD_LOGIC_VECTOR (127 downto 0);
		k21 : out  STD_LOGIC_VECTOR (127 downto 0);
		k22 : out  STD_LOGIC_VECTOR (127 downto 0);
		k23 : out  STD_LOGIC_VECTOR (127 downto 0);
		k24 : out  STD_LOGIC_VECTOR (127 downto 0);
		k25 : out  STD_LOGIC_VECTOR (127 downto 0);
		k26 : out  STD_LOGIC_VECTOR (127 downto 0);
		k27 : out  STD_LOGIC_VECTOR (127 downto 0);
		k28 : out  STD_LOGIC_VECTOR (127 downto 0);
		k29 : out  STD_LOGIC_VECTOR (127 downto 0);
		k30 : out  STD_LOGIC_VECTOR (127 downto 0);
		k31 : out  STD_LOGIC_VECTOR (127 downto 0);
		k32 : out  STD_LOGIC_VECTOR (127 downto 0));
end key_schedule;
architecture Behavioral of key_schedule is
component rl11x32 is
    Port ( wi_8 : in  STD_LOGIC_VECTOR (31 downto 0);
		wi_5 : in  STD_LOGIC_VECTOR (31 downto 0);
		wi_3 : in  STD_LOGIC_VECTOR (31 downto 0);
		wi_1 : in  STD_LOGIC_VECTOR (31 downto 0);
		i : in  STD_LOGIC_VECTOR (31 downto 0);
		o : out  STD_LOGIC_VECTOR (31 downto 0));
end component rl11x32;

component Sbox0set is
    Port ( si : in  STD_LOGIC_VECTOR (127 downto 0);
		so : out  STD_LOGIC_VECTOR (127 downto 0));
end component Sbox0set;

component Sbox1set is
    Port ( si : in  STD_LOGIC_VECTOR (127 downto 0);
		so : out  STD_LOGIC_VECTOR (127 downto 0));
end component Sbox1set;

component Sbox2set is
    Port ( si : in  STD_LOGIC_VECTOR (127 downto 0);
		so : out  STD_LOGIC_VECTOR (127 downto 0));
end component Sbox2set;

component Sbox3set is
    Port ( si : in  STD_LOGIC_VECTOR (127 downto 0);
		so : out  STD_LOGIC_VECTOR (127 downto 0));
end component Sbox3set;

component Sbox4set is
    Port ( si : in  STD_LOGIC_VECTOR (127 downto 0);
		so : out  STD_LOGIC_VECTOR (127 downto 0));
end component Sbox4set;

component Sbox5set is
    Port ( si : in  STD_LOGIC_VECTOR (127 downto 0);
		so : out  STD_LOGIC_VECTOR (127 downto 0));
end component Sbox5set;

component Sbox6set is
    Port ( si : in  STD_LOGIC_VECTOR (127 downto 0);
		so : out  STD_LOGIC_VECTOR (127 downto 0));
end component Sbox6set;

component Sbox7set is
    Port ( si : in  STD_LOGIC_VECTOR (127 downto 0);
		so : out  STD_LOGIC_VECTOR (127 downto 0));
end component Sbox7set;

signal wm8, wm7, wm6, wm5, wm4, wm3, wm2, wm1, w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14, w15, w16, w17, w18, w19, w20, w21, w22, w23, w24, w25, w26, w27, w28, w29, w30, w31, w32, w33, w34, w35, w36, w37, w38, w39, w40, w41, w42, w43, w44, w45, w46, w47, w48, w49, w50, w51, w52, w53, w54, w55, w56, w57, w58, w59, w60, w61, w62, w63, w64, w65, w66, w67, w68, w69, w70, w71, w72, w73, w74, w75, w76, w77, w78, w79, w80, w81, w82, w83, w84, w85, w86, w87, w88, w89, w90, w91, w92, w93, w94, w95, w96, w97, w98, w99, w100, w101, w102, w103, w104, w105, w106, w107, w108, w109, w110, w111, w112, w113, w114, w115, w116, w117, w118, w119, w120, w121, w122, w123, w124, w125, w126, w127, w128, w129, w130, w131 : STD_LOGIC_VECTOR (31 downto 0); 
signal wh1, wh2, wh3, wh4, wh5, wh6, wh7, wh8, wh9, wh10, wh11, wh12, wh13, wh14, wh15, wh16, wh17, wh18, wh19, wh20, wh21, wh22, wh23, wh24, wh25, wh26, wh27, wh28, wh29, wh30, wh31, wh32, wh33 : STD_LOGIC_VECTOR (127 downto 0);

begin
ob0: rl11x32 port map (wm8,wm5,wm3,wm1,"00000000000000000000000000000000",w0);
ob1: rl11x32 port map (wm7,wm4,wm2,w0,"00000000000000000000000000000001",w1);
ob2: rl11x32 port map (wm6,wm3,wm1,w1,"00000000000000000000000000000010",w2);
ob3: rl11x32 port map (wm5,wm2,w0,w2,"00000000000000000000000000000011",w3);
ob4: rl11x32 port map (wm4,wm1,w1,w3,"00000000000000000000000000000100",w4);
ob5: rl11x32 port map (wm3,w0,w2,w4,"00000000000000000000000000000101",w5);
ob6: rl11x32 port map (wm2,w1,w3,w5,"00000000000000000000000000000110",w6);
ob7: rl11x32 port map (wm1,w2,w4,w6,"00000000000000000000000000000111",w7);
ob8: rl11x32 port map (w0,w3,w5,w7,"00000000000000000000000000001000",w8);
ob9: rl11x32 port map (w1,w4,w6,w8,"00000000000000000000000000001001",w9);
ob10: rl11x32 port map (w2,w5,w7,w9,"00000000000000000000000000001010",w10);
ob11: rl11x32 port map (w3,w6,w8,w10,"00000000000000000000000000001011",w11);
ob12: rl11x32 port map (w4,w7,w9,w11,"00000000000000000000000000001100",w12);
ob13: rl11x32 port map (w5,w8,w0,w12,"00000000000000000000000000001101",w13);
ob14: rl11x32 port map (w6,w9,w11,w13,"00000000000000000000000000001110",w14);
ob15: rl11x32 port map (w7,w10,w12,w14,"00000000000000000000000000001111",w15);
ob16: rl11x32 port map (w8,w11,w13,w15,"00000000000000000000000000010000",w16);
ob17: rl11x32 port map (w9,w12,w14,w16,"00000000000000000000000000010001",w17);
ob18: rl11x32 port map (w10,w13,w15,w17,"00000000000000000000000000010010",w18);
ob19: rl11x32 port map (w11,w14,w16,w18,"00000000000000000000000000010011",w19);
ob20: rl11x32 port map (w12,w15,w17,w19,"00000000000000000000000000010100",w20);
ob21: rl11x32 port map (w13,w16,w18,w20,"00000000000000000000000000010101",w21);
ob22: rl11x32 port map (w14,w17,w19,w21,"00000000000000000000000000010110",w22);
ob23: rl11x32 port map (w15,w18,w20,w22,"00000000000000000000000000010111",w23);
ob24: rl11x32 port map (w16,w19,w21,w23,"00000000000000000000000000011000",w24);
ob25: rl11x32 port map (w17,w20,w22,w24,"00000000000000000000000000011001",w25);
ob26: rl11x32 port map (w18,w21,w23,w25,"00000000000000000000000000011010",w26);
ob27: rl11x32 port map (w19,w22,w24,w26,"00000000000000000000000000011011",w27);
ob28: rl11x32 port map (w20,w23,w25,w27,"00000000000000000000000000011100",w28);
ob29: rl11x32 port map (w21,w24,w26,w28,"00000000000000000000000000011101",w29);
ob30: rl11x32 port map (w22,w25,w27,w29,"00000000000000000000000000011110",w30);
ob31: rl11x32 port map (w23,w26,w28,w30,"00000000000000000000000000011111",w31);
ob32: rl11x32 port map (w24,w27,w29,w31,"00000000000000000000000000100000",w32);
ob33: rl11x32 port map (w25,w28,w30,w32,"00000000000000000000000000100001",w33);
ob34: rl11x32 port map (w26,w29,w31,w33,"00000000000000000000000000100010",w34);
ob35: rl11x32 port map (w27,w30,w32,w34,"00000000000000000000000000100011",w35);
ob36: rl11x32 port map (w28,w31,w33,w35,"00000000000000000000000000100100",w36);
ob37: rl11x32 port map (w29,w32,w34,w36,"00000000000000000000000000100101",w37);
ob38: rl11x32 port map (w30,w33,w35,w37,"00000000000000000000000000100110",w38);
ob39: rl11x32 port map (w31,w34,w36,w38,"00000000000000000000000000100111",w39);
ob40: rl11x32 port map (w32,w35,w37,w39,"00000000000000000000000000101000",w40);
ob41: rl11x32 port map (w33,w36,w38,w40,"00000000000000000000000000101001",w41);
ob42: rl11x32 port map (w34,w37,w39,w41,"00000000000000000000000000101010",w42);
ob43: rl11x32 port map (w35,w38,w40,w42,"00000000000000000000000000101011",w43);
ob44: rl11x32 port map (w36,w39,w41,w43,"00000000000000000000000000101100",w44);
ob45: rl11x32 port map (w37,w40,w42,w44,"00000000000000000000000000101101",w45);
ob46: rl11x32 port map (w38,w41,w43,w45,"00000000000000000000000000101110",w46);
ob47: rl11x32 port map (w39,w42,w44,w46,"00000000000000000000000000101111",w47);
ob48: rl11x32 port map (w40,w43,w45,w47,"00000000000000000000000000110000",w48);
ob49: rl11x32 port map (w41,w44,w46,w48,"00000000000000000000000000110001",w49);
ob50: rl11x32 port map (w42,w45,w47,w49,"00000000000000000000000000110010",w50);
ob51: rl11x32 port map (w43,w46,w48,w50,"00000000000000000000000000110011",w51);
ob52: rl11x32 port map (w44,w47,w49,w51,"00000000000000000000000000110100",w52);
ob53: rl11x32 port map (w45,w48,w50,w52,"00000000000000000000000000110101",w53);
ob54: rl11x32 port map (w46,w49,w51,w53,"00000000000000000000000000110110",w54);
ob55: rl11x32 port map (w47,w50,w52,w54,"00000000000000000000000000110111",w55);
ob56: rl11x32 port map (w48,w51,w63,w55,"00000000000000000000000000111000",w56);
ob57: rl11x32 port map (w49,w52,w64,w56,"00000000000000000000000000111001",w57);
ob58: rl11x32 port map (w50,w53,w65,w57,"00000000000000000000000000111010",w58);
ob59: rl11x32 port map (w51,w54,w66,w58,"00000000000000000000000000111011",w59);
ob60: rl11x32 port map (w52,w55,w67,w59,"00000000000000000000000000111100",w60);
ob61: rl11x32 port map (w53,w56,w68,w60,"00000000000000000000000000111101",w61);
ob62: rl11x32 port map (w54,w57,w69,w61,"00000000000000000000000000111110",w62);
ob63: rl11x32 port map (w55,w58,w60,w62,"00000000000000000000000000111111",w63);
ob64: rl11x32 port map (w56,w59,w61,w63,"00000000000000000000000001000000",w64);
ob65: rl11x32 port map (w57,w60,w62,w64,"00000000000000000000000001000001",w65);
ob66: rl11x32 port map (w58,w61,w63,w65,"00000000000000000000000001000010",w66);
ob67: rl11x32 port map (w59,w62,w64,w66,"00000000000000000000000001000011",w67);
ob68: rl11x32 port map (w60,w63,w65,w67,"00000000000000000000000001000100",w68);
ob69: rl11x32 port map (w61,w64,w66,w68,"00000000000000000000000001000101",w69);
ob70: rl11x32 port map (w62,w65,w67,w69,"00000000000000000000000001000110",w70);
ob71: rl11x32 port map (w63,w66,w68,w70,"00000000000000000000000001000111",w71);
ob72: rl11x32 port map (w64,w67,w69,w71,"00000000000000000000000001001000",w72);
ob73: rl11x32 port map (w65,w68,w70,w72,"00000000000000000000000001001001",w73);
ob74: rl11x32 port map (w66,w69,w71,w73,"00000000000000000000000001001010",w74);
ob75: rl11x32 port map (w67,w70,w72,w74,"00000000000000000000000001001011",w75);
ob76: rl11x32 port map (w68,w71,w73,w75,"00000000000000000000000001001100",w76);
ob77: rl11x32 port map (w69,w72,w74,w76,"00000000000000000000000001001101",w77);
ob78: rl11x32 port map (w70,w73,w75,w77,"00000000000000000000000001001110",w78);
ob79: rl11x32 port map (w71,w74,w76,w78,"00000000000000000000000001001111",w79);
ob80: rl11x32 port map (w72,w75,w77,w79,"00000000000000000000000001010000",w80);
ob81: rl11x32 port map (w73,w76,w78,w80,"00000000000000000000000001010001",w81);
ob82: rl11x32 port map (w74,w77,w79,w81,"00000000000000000000000001010010",w82);
ob83: rl11x32 port map (w75,w78,w80,w82,"00000000000000000000000001010011",w83);
ob84: rl11x32 port map (w76,w79,w81,w83,"00000000000000000000000001010100",w84);
ob85: rl11x32 port map (w77,w80,w82,w84,"00000000000000000000000001010101",w85);
ob86: rl11x32 port map (w78,w81,w83,w85,"00000000000000000000000001010110",w86);
ob87: rl11x32 port map (w79,w82,w84,w86,"00000000000000000000000001010111",w87);
ob88: rl11x32 port map (w80,w83,w85,w87,"00000000000000000000000001011000",w88);
ob89: rl11x32 port map (w81,w84,w86,w88,"00000000000000000000000001011001",w89);
ob90: rl11x32 port map (w82,w85,w87,w89,"00000000000000000000000001011010",w90);
ob91: rl11x32 port map (w83,w86,w88,w90,"00000000000000000000000001011011",w91);
ob92: rl11x32 port map (w84,w87,w89,w91,"00000000000000000000000001011100",w92);
ob93: rl11x32 port map (w85,w88,w90,w92,"00000000000000000000000001011101",w93);
ob94: rl11x32 port map (w86,w89,w91,w93,"00000000000000000000000001011110",w94);
ob95: rl11x32 port map (w87,w90,w92,w94,"00000000000000000000000001011111",w95);
ob96: rl11x32 port map (w88,w91,w93,w95,"00000000000000000000000001100000",w96);
ob97: rl11x32 port map (w89,w92,w94,w96,"00000000000000000000000001100001",w97);
ob98: rl11x32 port map (w90,w93,w95,w97,"00000000000000000000000001100010",w98);
ob99: rl11x32 port map (w91,w94,w96,w98,"00000000000000000000000001100011",w99);
ob100: rl11x32 port map (w92,w95,w97,w99,"00000000000000000000000001100100",w100);
ob101: rl11x32 port map (w93,w96,w98,w100,"00000000000000000000000001100101",w101);
ob102: rl11x32 port map (w94,w97,w99,w101,"00000000000000000000000001100110",w102);
ob103: rl11x32 port map (w95,w98,w100,w102,"00000000000000000000000001100111",w103);
ob104: rl11x32 port map (w96,w99,w101,w103,"00000000000000000000000001101000",w104);
ob105: rl11x32 port map (w97,w100,w102,w104,"00000000000000000000000001101001",w105);
ob106: rl11x32 port map (w98,w101,w103,w105,"00000000000000000000000001101010",w106);
ob107: rl11x32 port map (w99,w102,w104,w106,"00000000000000000000000001101011",w107);
ob108: rl11x32 port map (w100,w103,w105,w107,"00000000000000000000000001101100",w108);
ob109: rl11x32 port map (w101,w104,w106,w108,"00000000000000000000000001101101",w109);
ob110: rl11x32 port map (w102,w105,w107,w109,"00000000000000000000000001101110",w110);
ob111: rl11x32 port map (w103,w106,w108,w110,"00000000000000000000000001101111",w111);
ob112: rl11x32 port map (w104,w107,w109,w111,"00000000000000000000000001110000",w112);
ob113: rl11x32 port map (w105,w108,w110,w112,"00000000000000000000000001110001",w113);
ob114: rl11x32 port map (w106,w109,w111,w113,"00000000000000000000000001110010",w114);
ob115: rl11x32 port map (w107,w110,w112,w114,"00000000000000000000000001110011",w115);
ob116: rl11x32 port map (w108,w111,w113,w115,"00000000000000000000000001110100",w116);
ob117: rl11x32 port map (w109,w112,w114,w116,"00000000000000000000000001110101",w117);
ob118: rl11x32 port map (w110,w113,w115,w117,"00000000000000000000000001110110",w118);
ob119: rl11x32 port map (w111,w114,w116,w118,"00000000000000000000000001110111",w119);
ob120: rl11x32 port map (w112,w115,w117,w119,"00000000000000000000000001111000",w120);
ob121: rl11x32 port map (w113,w116,w118,w120,"00000000000000000000000001111001",w121);
ob122: rl11x32 port map (w114,w117,w119,w121,"00000000000000000000000001111010",w122);
ob123: rl11x32 port map (w115,w118,w120,w122,"00000000000000000000000001111011",w123);
ob124: rl11x32 port map (w116,w119,w121,w123,"00000000000000000000000001111100",w124);
ob125: rl11x32 port map (w117,w120,w122,w124,"00000000000000000000000001111101",w125);
ob126: rl11x32 port map (w118,w121,w123,w125,"00000000000000000000000001111110",w126);
ob127: rl11x32 port map (w119,w122,w124,w126,"00000000000000000000000001111111",w127);
ob128: rl11x32 port map (w120,w123,w125,w127,"00000000000000000000000010000000",w128);
ob129: rl11x32 port map (w121,w124,w126,w128,"00000000000000000000000010000001",w129);
ob130: rl11x32 port map (w122,w125,w127,w129,"00000000000000000000000010000010",w130);
ob131: rl11x32 port map (w123,w126,w128,w130,"00000000000000000000000010000011",w131);

wh1<=w0&w1&w2&w3;
sk0: Sbox3set port map (wh1,k0);  
wh2<=w4&w5&w6&w7;
sk1: Sbox2set port map (wh2,k1);  
wh3<=w8&w9&w10&w11;
sk2: Sbox1set port map (wh3,k2);
wh4<=w12&w13&w14&w15;
sk3: Sbox0set port map (wh4,k3); 
wh5<=w16&w17&w18&w19;
sk4: Sbox7set port map (wh5,k4);
wh6<=w20&w21&w22&w23;
sk5: Sbox6set port map (wh6,k5);
wh7<= w24&w25&w26&w27;
sk6: Sbox5set port map (wh7,k6);
wh8<=w28&w29&w30&w31;
sk7: Sbox4set port map (wh8,k7);
wh9<=w32&w33&w34&w35;
sk8: Sbox3set port map (wh9,k8);
wh10<=w36&w37&w38&w39;
sk9: Sbox2set port map (wh10,k9);
wh11<=w40&w41&w42&w43;
sk10: Sbox1set port map (wh11,k10);
wh12<=w44&w45&w46&w47;
sk11: Sbox0set port map (wh12,k11);
wh13<=w48&w49&w50&w51;
sk12: Sbox7set port map (wh13,k12);
wh14<=w52&w53&w54&w55;
sk13: Sbox6set port map (wh14,k13);
wh15<=w56&w57&w58&w59;
sk14: Sbox5set port map (wh15,k14);
wh16<=w60&w61&w62&w63;
sk15: Sbox4set port map (wh16,k15);
wh17<=w64&w65&w66&w67;
sk16: Sbox3set port map (wh17,k16);
wh18<=w68&w69&w70&w71;
sk17: Sbox2set port map (wh18,k17);
wh19<=w72&w73&w74&w75;
sk18: Sbox1set port map (wh19,k18);
wh20<=w76&w77&w78&w79;
sk19: Sbox0set port map (wh20,k19);
wh21<=w80&w81&w82&w83;
sk20: Sbox7set port map (wh21,k20);
wh22<=w84&w85&w86&w87;
sk21: Sbox6set port map (wh22,k21);
wh23<=w88&w89&w90&w91;
sk22: Sbox5set port map (wh23,k22);
wh24<=w92&w93&w94&w95;
sk23: Sbox4set port map (wh24,k23);
wh25<=w96&w97&w98&w99;
sk24: Sbox3set port map (wh15,k24);
wh26<=w100&w101&w102&w103;
sk25: Sbox2set port map (wh26,k25);
wh27<=w104&w105&w106&w107;
sk26: Sbox1set port map (wh27,k26);
wh28<=w108&w109&w110&w111;
sk27: Sbox0set port map (wh28,k27);
wh29<=w112&w113&w114&w115;
sk28: Sbox7set port map (wh29,k28);
wh30<=w116&w117&w118&w119;
sk29: Sbox6set port map (wh30,k29);
wh31<= w120&w121&w122&w123;
sk30: Sbox5set port map (wh31,k30);
wh32<=w124&w125&w126&w127;
sk31: Sbox4set port map (wh32,k31);
wh33<=w128&w129&w130&w131;
sk32: Sbox3set port map (wh33,k32);
end Behavioral;